<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="box">
        <span>{{title}}</title></span>
        <span>{{fun()}}</title></span>
        <p v-text ="htmlContent">这里内容不生效</p>
        <p v-html ="htmlContent">这里内容不生效</p>
        <!-- 渲染指令 -->
        <p v-for="(item,key,index) in arr">这是数组内容{{item+" key="+key+ " index="+index+" value="+item}}</p>
        <p v-if="create">销毁还是创建</p>
        <p v-show="create">visible or hide</p>
        <!-- 属性绑定 -->
        <p v-bind:title="title">绑定了title</p>
        <p :title="title">绑定了title</p>

        <!-- 事件指令 -->
        <button v-on:click="clickfun">CLICK ME</button>
        <button :click="clickfun">CLICK ME</button>

        <!-- 表单指令 -->
        <div>
            <span>没带修饰符trim</span><input type="text" v-model="inputValue">
        <span v-text="inputValue"></span></div>
        <!-- 修饰符 -->
        <div><span>带修饰符trim</span><input type="text" v-model.trim="inputValue"></div>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.7.14"></script>
    <script>
        // 1.响应式和插值表达式
        const vm = new Vue({
            el: '#box',
            data() {
                return {
                    title: 'this is title',
                    htmlContent:"<p style='color:red'>this is content</p>",
                    arr:['a','b','c'],
                    create: true,
                    inputValue:"default"

                }
            },
            methods:{
                fun(){
                    return 'this is fun'
                },
                clickfun(){
                    alert("click bind")
                }
            },
            computed:{
                computeTitle(){
                    return 'modify '+this.title
                }
            },
            // 3.侦听器
            watch:{
                htmlContent(newVal,oldVal){
                    console.log(newVal,oldVal)
                }
            }
        })
    </script>
</body>

</html>